package com.example.meterialproject.activitys.transition.demo1

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatImageView
import androidx.core.os.bundleOf
import androidx.core.view.ViewCompat
import androidx.fragment.app.Fragment
import coil.load
import com.example.meterialproject.R
import kotlinx.android.synthetic.main.fragment_transition_first_to.*

/**
 *
 * @ClassName: TransitionDemo1Fragment
 * @Author: android 超级兵
 * @CreateDate: 4/26/22$ 2:21 PM$
 * TODO
 */
class TransitionDemoTo1Fragment : Fragment() {

    companion object {
        const val URL = "URL"
        const val TAG = "TransitionDemoTo1Fragment"

        fun newInstance(url: String) = let {
            TransitionDemoTo1Fragment().apply {
                arguments = bundleOf(
                    URL to url,
                )
            }
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?,
    ): View? {
        return inflater.inflate(R.layout.fragment_transition_first_to, container, false)
    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        view.findViewById<AppCompatImageView>(R.id.imageSharedElement)
            .apply {
                load(requireArguments().getString(URL))
                ViewCompat.setTransitionName(parentView, requireArguments().getString(URL))
            }
    }


}